﻿@using KPIS.GERP.Models
@model KPIS.GERP.Models.ICM.MovementDtl

@{
    ViewBag.Title = "โอนย้าย";
    ViewBag.Descr = "เพิ่มข้อมูลการโอนย้าย";
}

@using (Html.BeginForm("CreateMovementDtl", "Movement", new { MovementId = Model.MovementId }, FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()

    <div class="block-button-menu-above">
        @Html.ActionLink("กลับไปหน้าแสดงข้อมูล", "IndexMovementDtl", new { MovementId = Model.MovementId}
                        , new { @class = "btn btn-gray button-standard-width btn-small", role="button" })
        @Html.ButtonSubmit()
        @Html.ActionLink("ยกเลิก", "IndexMovementDtl", new { MovementId = Model.MovementId }
                        , new { @class = "btn btn-danger button-standard-width btn-small", role="button" })
    </div>
    
     <div id="errormsg" class="alert-error">@Html.ValidationSummary()</div>
     @Html.Partial("_EditorFormMovementDtl")
}

@section scripts
{
    <script>

        $('#lenderType').val('');
        $(function lender() {
            $('#MoveQty').val('');
            $('#MoveQty').keyup(function () {
                var num1 = parseInt($('#MoveQty').val());
                var num2 = parseInt($('#QuantityVal').html());
                if (isNaN(num1)) {
                    return 0;
                }
                else if (num1 > num2) {
                    alert('จำนวนที่โอนต้องไม่มากกว่าจำนวนทั้งหมด');
                    $('#MoveQty').val('');
                }
                else if (num1 == 0) {
                    alert('จำนวนที่โอนต้องไม่น้อยกว่า  1');
                    $('#MoveQty').val('');
                }
                else {
                    return;
                }
            });

            $('#lenderType').change(function () {
                getResult($('#lenderType').val());
            });
        });

        function getResult(AssetId) {
            $.ajax({
                url: '@Url.Action("AssetUnit")',
                type: 'GET',
                cache: false,
                data: { AssetId: $('#lenderType').val() },
                success: function (result) {
                    $('#QuantityVal').html(result.Quantity);
                    $('#Description').html(result.Description);
                    $('#UnitName').html(result.UnitName);
                }
            });
        }

        $("form").submit(function (e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm('บันทึกข้อมูลใช่หรือไม่', function (result) {
                if (result) {
                    currentForm.submit();
                }
                else {
                   
                }
            });
        });
    </script>
}